package com.ruoyi.heima.controller;


import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import java.util.List;
import com.ruoyi.heima.domain.po.NewsType;
import com.ruoyi.heima.service.INewsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.heima.service.INewsTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * newsController
 * 
 * @author weiyi
 * @date 2025-06-21
 */
@RestController
@RequestMapping("/newsType")
public class NewsTypeController extends BaseController
{
    @Autowired
    private INewsTypeService newsTypeService;

    /**
     * 查询news列表
     */

    @GetMapping("/all")
    public List<NewsType> newsAll()
    {
        return newsTypeService.lambdaQuery().list();
    }
/**
 * 分页查询news表
 */
    @GetMapping("/list")
    public TableDataInfo  pageNewsType(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                       @RequestParam(value = "typeName",required = false) String typeName){
        return newsTypeService.pageNewsType(pageNum,pageSize,typeName);
    }

    /**
     * 新增新闻类型
     */
    @PostMapping
    public AjaxResult add(@RequestBody NewsType newsType) {
        return AjaxResult.success(newsTypeService.insertNewsType(newsType));
    }

    /**
     * 根据新闻类型ID查询新闻类型
     *
     * @param typeId 新闻类型ID
     * @return AjaxResult 结果
     */
    @GetMapping("/{newsTypeId}")
    public AjaxResult getNewsType(@PathVariable("newsTypeId") Long typeId) {
        return AjaxResult.success(newsTypeService.getById(typeId));
    }

    /**
     * 修改新闻类型
     *
     * @param newsType 新闻类型
     * @return AjaxResult 结果
     */

    @PutMapping
    public AjaxResult edit(@RequestBody NewsType newsType) {
        return AjaxResult.success(newsTypeService.updateNewsType(newsType));
    }

    /**
     * 删除新闻类型
     *
     * @param typeIds 需要删除的新闻类型ID
     * @return AjaxResult 结果
     */

    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds) {
        return AjaxResult.success(newsTypeService.deleteNewsTypeByTypeIds(typeIds));
    }
}
